package com.yy.job.common.utils.date;

import java.text.SimpleDateFormat;
import java.util.Date;

public class YYDateUtils {
	
	public static int getIntervalDay(Date startDate, Date endDate) {
		long startTime = startDate.getTime();
		long endTime = endDate.getTime();
		return getIntervalDay(startTime, endTime);
	}

	public static int getIntervalDay(long startdate, long enddate) {
		long interval = enddate - startdate;
		int intervalday = (int) (interval / 86400000L);
		return intervalday;
	}

	public static int getIntervalHour(Date startDate, Date endDate) {
		long startTime = startDate.getTime();
		long endTime = endDate.getTime();
		return getIntervalHour(startTime, endTime);
	}

	public static int getIntervalHour(long startdate, long enddate) {
		long interval = enddate - startdate;
		int intervalHour = (int) (interval / 3600000L);
		return intervalHour;
	}

	public static int getIntervalMinute(Date startDate, Date endDate) {
		long startTime = startDate.getTime();
		long endTime = endDate.getTime();
		return getIntervalMinute(startTime, endTime);
	}

	public static int getIntervalMinute(long startdate, long enddate) {
		long interval = enddate - startdate;
		int intervalMinute = (int) (interval / 60000L);
		return intervalMinute;
	}

	public static int getIntervalSecond(Date startDate, Date endDate) {
		long startTime = startDate.getTime();
		long endTime = endDate.getTime();
		return getIntervalSecond(startTime, endTime);
	}

	public static int getIntervalSecond(long startdate, long enddate) {
		long interval = enddate - startdate;
		int intervalMinute = (int) (interval / 1000L);
		return intervalMinute;
	}

	public static String formatDateTimeDefault(Date date) {
		return format(date, DateFormatTemplate.DATE_TIME_FORMAT_DEFAULT);
	}

	public static String format(Date date, String format) {
		if (date == null) {
			return null;
		}
		SimpleDateFormat df = new SimpleDateFormat(format);
		return df.format(date);
	}
}
